package pomodorotasks.testutils

import griffon.core.UIThreadManager

/**
 * Utility methods for threading
 * @author Dawid Pytel
 */
class ThreadingUtils {
    
    /**
     * Wait for async operations in swing thread. Method assumes that tasks are 
     * executed in a sequence.
     */
    public static void waitForAsyncOperationsComplete() {
        assert ! UIThreadManager.INSTANCE.isUIThread()
        def lock = new Object()
        UIThreadManager.INSTANCE.executeAsync{synchronized(lock) {lock.notifyAll()}}
        synchronized(lock) {lock.wait()}
    }
}

